package com.amex.uam.dao.impl;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.jdbc.core.RowMapper;

import com.amex.uam.util.Utils;

public class SimpleRowMapper implements RowMapper<Map<String, String>> {
	public Map<String, String> mapRow(ResultSet rs, int rowNum) throws SQLException {
		Map<String, String> userMap = new HashMap<String, String>();
		ResultSetMetaData meta = rs.getMetaData();
		int columnCount = meta.getColumnCount();
		for (int i = 1; i <= columnCount; i++) {
			String key = meta.getColumnName(i);
			String val;
			String className = meta.getColumnClassName(i);
			if ("java.sql.Timestamp".equals(className)) {
				val = Utils.formatDatetime(rs.getTimestamp(i));
			} else {
				val = rs.getString(key);
			}
			
			userMap.put(key, (val == null) ? "" : val.trim());
		}
		return userMap;
	}
	
}
